package com.qq.xqj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qq.xqj.modle.Car_info;
import com.qq.xqj.service.impl.Car_serviceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/car")
public class Car_controller {
    @Autowired
    Car_serviceImpl car_serviceImpl;

    @GetMapping("/pageCar")
    private String getCarInfo(Model model ,@RequestParam(defaultValue="1",value = "pageNum")Integer pageNum){
        PageHelper.startPage(pageNum,6);
        List<Car_info> list =  car_serviceImpl.getCarInfo();
        System.out.println("list"+list);
        PageInfo<Car_info> car_infoPageInfo = new PageInfo<>(list);
        System.out.println("car_"+car_infoPageInfo);
        model.addAttribute("pageInfo",car_infoPageInfo);

        return "xqj/carInfo";
    }

    @RequestMapping("/selectCarByKey")
    public String selectCarByKey(Car_info car_info, @RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum, ModelMap map){
        PageHelper.startPage(pageNum,6);
        List<Car_info> car_infos = car_serviceImpl.selectCarByKey(car_info);
        PageInfo<Car_info> car_infoPageInfo = new PageInfo<>(car_infos);
        map.addAttribute("pageInfo",car_infoPageInfo);
        return "xqj/carInfo";
    }

    @RequestMapping("/queryCar/{id}")
    public String queryCar(@PathVariable Integer id,Model m){
        System.out.println(id);
        m.addAttribute("cars",car_serviceImpl.queryCarById(id));
        return "xqj/add";

    }


}
